﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace sy1_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 窗体加载时让 Label 水平居中
        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Left = (this.Width - label1.Width) / 2;
        }

        // Timer 每隔一段时间触发一次
        private void timer1_Tick(object sender, EventArgs e)
        {
            // 向下移动（Top 增加）
            label1.Top += 5;

            // 判断是否超出窗体底部
            if (label1.Top > this.Height)
            {
                // 回到顶部
                label1.Top = 0;
            }
        }

        // 按钮点击切换 Timer 启停
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = !timer1.Enabled;
            button1.Text = timer1.Enabled ? "停止动画" : "开始动画";
        }

        // 鼠标进入 Label 时变色
        private void label1_MouseEnter(object sender, EventArgs e)
        {
            label1.ForeColor = Color.Red;
        }

        // 鼠标离开 Label 时恢复颜色
        private void label1_MouseLeave(object sender, EventArgs e)
        {
            label1.ForeColor = Color.Black;
        }
    }
}